package com.careercup.question.id4570783653298176;

import java.util.Scanner;

public class Solution {
	private static final int INF = Integer.MAX_VALUE, MAX_N = 100;
	private static int solve(int a[]) {
	    int b[] = new int[2 * MAX_N + 1];

	    for (int i = -a.length; i <= a.length; ++i)
	        b[MAX_N + i] = INF;

	    int result = 0;
	    for (int i = 0, count = 0; i < a.length; ++i) {
	        count += a[i] > 0 ? 1 : -1;
	        result = Math.max(i - b[MAX_N + count], result);
	        b[MAX_N + count] = Math.min(i, b[MAX_N + count]);
	    }

	    return result;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a[] = new int[in.nextInt()];
		for(int i = 0; i < a.length; i++)
			a[i] = in.nextInt();
		System.out.println(solve(a));
	}
}
